package com.huidu.bitrade.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.huidu.bitrade.config.ChargeRecommendConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Optional;

/**
 * 推荐手续费奖励枚举
 */
@Getter
@AllArgsConstructor
public enum ChargeRecommendEnum {

    LEVEL_ONE(BigDecimal.valueOf(0.05),1,"一星"),
    LEVEL_TWO(BigDecimal.valueOf(0.10),2,"二星"),
    LEVEL_THREE(BigDecimal.valueOf(0.20),3,"三星"),
    LEVEL_FOUR(BigDecimal.valueOf(0.30),4,"四星"),
    LEVEL_FIVE(BigDecimal.valueOf(0.40),5,"五星"),
    LEVEL_SIX(BigDecimal.valueOf(0.50),6,"六星"),
    LEVEL_SEVEN(BigDecimal.valueOf(0.60),7,"七星");

    public static void update(ChargeRecommendConfig chargeRecommendConfig){
        Integer level = chargeRecommendConfig.getLevel();
        switch (level){
            case 1:
                update(LEVEL_ONE,chargeRecommendConfig);
                break;
            case 2:
                update(LEVEL_TWO,chargeRecommendConfig);
                break;
            case 3:
                update(LEVEL_THREE,chargeRecommendConfig);
                break;
            case 4:
                update(LEVEL_FOUR,chargeRecommendConfig);
                break;
            case 5:
                update(LEVEL_FIVE,chargeRecommendConfig);
                break;
            case 6:
                update(LEVEL_SIX,chargeRecommendConfig);
                break;
            case 7:
                update(LEVEL_SEVEN,chargeRecommendConfig);
                break;
        }
    }

    private static void update(ChargeRecommendEnum starChargeEnum, ChargeRecommendConfig chargeRecommendConfig){
        starChargeEnum.ratio = chargeRecommendConfig.getRatio();
        starChargeEnum.levelName = chargeRecommendConfig.getLevelName();
        starChargeEnum.level = chargeRecommendConfig.getLevel();
    }

    public static ChargeRecommendEnum getByLevel(Integer level){
        Optional<ChargeRecommendEnum> any;
        any = Arrays.stream(ChargeRecommendEnum.class.getEnumConstants())
                .filter(e -> e.getLevel().equals(level)).findAny();
        return any.orElse(null);
    }

    /**
     * 奖励比例
     */
    private BigDecimal ratio;

    /**
     * 对应等级
     */
    @EnumValue
    private Integer level;

    /**
     * 等级名称
     */
    private String levelName;




}
